package cn.stylefeng.guns.modular.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.entity.Feedback;
import cn.stylefeng.guns.modular.entity.Order;
import cn.stylefeng.guns.modular.mapper.OrderMapper;
import cn.stylefeng.guns.modular.service.IOrderService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author XiangTianGe
 * @since 2020-04-14
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 获取订单列表
     */
    @Override
    public LayuiPageInfo getList(Page<Order> page, String keyword, String beginTime, String endTime, Integer type, Integer status, Long userId) {
        Page<Map<String, Object>> list = orderMapper.getList(page, keyword, beginTime, endTime, type, status, userId);
        list.getRecords().forEach(f -> {
            String order_status = f.get("order_status").toString();
            if (order_status.equals("1")) {
                f.put("order_status_name", "待支付");
            }
            if (order_status.equals("2")) {
                f.put("order_status_name", "支付完成");
            }
            if (order_status.equals("3")) {
                f.put("order_status_name", "已超时");
            }
        });
        return LayuiPageFactory.createPageInfo(list);
    }

    /**
     * 跳转订单首页
     */
    @Override
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView();
        // 已支付
        String payment = orderMapper.payment();
        if (payment == null) {
            modelAndView.addObject("payment", 0);
        } else {
            modelAndView.addObject("payment", payment);
        }
        // 未支付
        String unPayment = orderMapper.unPayment();
        if (unPayment == null) {
            modelAndView.addObject("unPayment", 0);
        } else {
            modelAndView.addObject("unPayment", unPayment);
        }
        return modelAndView;
    }
}
